/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uniriotec.pm.prova.core;

import java.util.List;
import uniriotec.pm.prova.api.TopicoService;
import uniriotec.pm.prova.dao.DAOFactory;
import uniriotec.pm.prova.dao.TopicoDAO;
import uniriotec.pm.prova.dto.QuestaoDTO;
import uniriotec.pm.prova.dto.TopicoDTO;
import uniriotec.pm.prova.util.DAOUtil;

/**
 *
 * @author albertoapr
 */
public class SimpleTopicoService implements TopicoService {

     private static DAOFactory factory = DAOUtil.getDAOFactory();
 
@Override
    public void create(TopicoDTO topico) {
        TopicoDAO dao = factory.getTopicoDAO();
        dao.create(topico);
    }

    @Override
    public void update(TopicoDTO topico) {
        TopicoDAO dao = factory.getTopicoDAO();
        dao.update(topico);
    }

    

    @Override
    public TopicoDTO searchById(int topicoId) {
        TopicoDAO dao = factory.getTopicoDAO();
        TopicoDTO topico = dao.searchById(topicoId);
        topico.setQuestoes(dao.listQuestoes(topicoId));
        return topico;
    }

    @Override
    public void remove(int topicoId) {
        TopicoDAO dao = factory.getTopicoDAO();
        dao.remove(topicoId);
    }

    

    @Override
    public List<QuestaoDTO> listQuestoes(int topicoId) {
        TopicoDAO dao = factory.getTopicoDAO();
        return (List<QuestaoDTO>) dao.listQuestoes(topicoId);
    }

    @Override
    public void addQuestao(int topicoId, int questaoId) {
        TopicoDAO dao = factory.getTopicoDAO();
        dao.addQuestao(topicoId, questaoId);
    }

    @Override
    public void removeQuestao(int topicoId, int questaoId) {
        TopicoDAO dao = factory.getTopicoDAO();
        dao.removeQuestao(topicoId, questaoId);
    }

    

}
